package cn.mumzone.pos.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.mumzone.basic.base.BaseActivity;
import cn.mumzone.pos.AppConstants;
import cn.mumzone.pos.BuildConfig;
import cn.mumzone.pos.R;
import cn.mumzone.pos.util.AppUtil;

/**
 * Created by qiuzhenhuan on 2019/7/1.
 */

public class ACT_Setting extends BaseActivity {

    @BindView(R.id.tv_user_name)
    TextView tvUserName;
    @BindView(R.id.tv_user_title)
    TextView tvUserTitle;
    @BindView(R.id.tv_shop_name)
    TextView tvShopName;
    @BindView(R.id.iv_new_version)
    ImageView ivNewVersion;
    @BindView(R.id.tv_app_version)
    TextView tvAppVerison;
    @BindView(R.id.tv_version)
    TextView tvVerison;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        overridePendingTransition(cn.mumzone.basic.R.anim.right_in, cn.mumzone.basic.R.anim.right_out);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.gravity = Gravity.RIGHT;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(params);
        getWindow().setBackgroundDrawableResource(R.color.bg_color);


    }

    @Override
    protected void initEventAndData() {

        tvUserName.setText(AppConstants.TEMP_USER_NAME);
        tvUserTitle.setText("收银员");
        tvShopName.setText(AppConstants.TEMP_SHOP_NAME);
        ivNewVersion.setVisibility(AppUtil.isNeedUpdate() ? View.VISIBLE : View.GONE);
        tvAppVerison.setText(String.format("圣旦收银台v%s", BuildConfig.VERSION_NAME));
        tvVerison.setText(String.format("v%s", BuildConfig.VERSION_NAME));

    }

    @OnClick({R.id.iv_close, R.id.v_update_pwd_bg, R.id.v_version_bg, R.id.v_config_bg, R.id.v_off_work_bg})
    void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_close:
                finish();
                break;
            case R.id.v_update_pwd_bg:
                ACT_UpdatePwd.startAc(mContext);
                finish();
                break;
            case R.id.v_version_bg:
                ACT_VersionInfo.startAc(mContext);
                finish();
                break;
            case R.id.v_config_bg:
                if(AppConstants.TEMP_USER_PERMISSION!=null && AppConstants.TEMP_USER_PERMISSION.isSetting()){
                    ACT_ShopConfig.startAc(mContext);
                    finish();
                }else{
                    showError("您尚未开通相应权限 ~");
                }
                break;
            case R.id.v_off_work_bg:
                ACT_OffWork.startAc(mContext);
                finish();
                break;
        }
    }



    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(cn.mumzone.basic.R.anim.right_in, cn.mumzone.basic.R.anim.right_out);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected int getLayout() {
        return R.layout.act_setting;
    }

    public static void startAc(Context context) {
        Intent intent = new Intent(context, ACT_Setting.class);
        context.startActivity(intent);
    }

}
